Skip to content

Conversation

@alizaberger
Copy link
Collaborator

Describe your changes

This PR makes inserting links less confusing in the rich text view.

  1. The text highlighted was losing its highlight after clicking “Insert Link” so it was confusing what was being linked. This PR adds a grey highlight to the selected text while the Link Editor is active.
  2. Prepopulates the URL field with https://

PR Checklist

  • All new/changed functionality includes unit and (optionally) e2e tests as appropriate
  • All new/changed functions have /** ... */ docs
  • I've added the bug/enhancement and other labels as appropriate

Environment(s) tested

  • Device: [e.g. desktop, iPhone6, etc.]
  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context

Add any other context about the PR here.

@changeset-bot
Copy link

changeset-bot bot commented Apr 4, 2025

⚠️ No Changeset found

Latest commit: d8207e8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Apr 4, 2025

Deploy Preview for stacks-editor ready!

Name Link
🔨 Latest commit d8207e8
🔍 Latest deploy log https://app.netlify.com/sites/stacks-editor/deploys/67f6e1fae004510008ad8d17
😎 Deploy Preview https://deploy-preview-417--stacks-editor.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@dancormier dancormier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've taken a look at the code and tested the changes out. This is a nice improvement. The sort of little annoyance I've experienced dozens of times. Thanks for tackling this!

I only had one minor UI suggestion but I wouldn't let it hold up merging if you and/or others feel differently

null;
const linkMatch = /^http(s)?:\/\/\S+$/.exec(selectedText);
linkUrl = linkMatch?.length > 0 ? linkMatch[0] : "";
linkUrl = linkMatch?.length > 0 ? linkMatch[0] : "https://";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd find this a little less convenient because I'd paste a link here most often, so having the input prepopulated with https:// adds a step of deleting the text. Instead, my suggestion is to use the placeholder attribute with a value of https://… or something like "Add a link" similar to Google Docs:

image

I don't think the placeholder is entirely necessary as long as the Link URL field is focused upon invoking the link editor.

All this said, I'd like to get others' opinions on this since it's entirely possible this is just a me thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @dancormier. I don't think it is a good practice to prefill text input. Placeholders are a more conventional way of giving hints to users. I would recommend to check with your designer about this whole flow and seek their input. 🙂

Copy link
Contributor

@giamir giamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @alizaberger, for the PR! I noticed a small regression at the end of the flow—after the user clicks the save button, the popover with the link appears again, but the arrow is no longer pointing to the center of the link. See screenshots.

Before (see arrow centered)
Screenshot 2025-04-08 at 10 26 49

After (see arrow not centered anymore)
Screenshot 2025-04-08 at 10 27 41

I know @alexwarren did some work on links/popovers a while back, so you might want to rebase this branch. That might be all that’s needed to make the issue go away.

Apart from that, only minor things. Thanks for making the editor better. ❤️

this.hrefInput.value = state.url;
this.validate(state.url);

if (state.url != "https://") {
Copy link
Contributor

@giamir giamir Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Consider using identity (===) instead of equality (==) here. In JavaScript, == allows type coercion, which can lead to unexpected behavior—for example, 0 == '0' is true, but 0 === '0' is false. Using identity (===) ensures both the value and the type match, which tends to be safer and more predictable.

99.9% of the time in JS we should use identity (===) to avoid surprises. Quirks of an old language written in 10 days. 🙂

null;
const linkMatch = /^http(s)?:\/\/\S+$/.exec(selectedText);
linkUrl = linkMatch?.length > 0 ? linkMatch[0] : "";
linkUrl = linkMatch?.length > 0 ? linkMatch[0] : "https://";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @dancormier. I don't think it is a good practice to prefill text input. Placeholders are a more conventional way of giving hints to users. I would recommend to check with your designer about this whole flow and seek their input. 🙂

@alizaberger alizaberger requested a review from giamir April 9, 2025 21:11
@alizaberger alizaberger enabled auto-merge (squash) April 9, 2025 21:12
@alizaberger alizaberger merged commit 7c42d6e into main Apr 9, 2025
5 checks passed
@alizaberger alizaberger deleted the aberger/link-editor-selection-highlight branch April 9, 2025 21:12
@alizaberger
Copy link
Collaborator Author

Whoops, did not realize auto-merge would work without an approval! Sorry!

@giamir
Copy link
Contributor

giamir commented Apr 10, 2025

No problem, thanks for addressing the PR comments. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants